package com.chenjt.jvm.first.ten_GC;

/**
 * 注释：
 * 手动gc理解不可达对象的回收行为
 * -XX:+PrintGCDetails
 *
 * @author chenjt
 * @date 2025/6/16 10:13
 */
public class LocalVarGC {



    public void localVarGC2(){
        byte[] buffer = new byte[10 * 1024 * 1024];
        buffer = null;
        System.gc();
    }

    public void localVarGC3(){
        {
            byte[] buffer = new byte[10 * 1024 * 1024];
        }
        System.gc();
    }

    public void localVarGC4(){
        {
            byte[] buffer = new byte[10 * 1024 * 1024];
        }
        int value = 10;
        System.gc();
    }

    public void localVarGC1(){
        byte[] buffer = new byte[10 * 1024 * 1024];// 10MB
        System.gc();
    }
    public void localVarGC5(){
        localVarGC1();
        System.gc();
    }

    public static void main(String[] args) {
        LocalVarGC local = new LocalVarGC();
//        local.localVarGC1();
//        local.localVarGC2();
//        local.localVarGC3();
//        local.localVarGC4();
        local.localVarGC5();
    }


}
